package com.it.park.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.it.park.client.service.LinkService;
import com.it.park.client.service.VisitInfoService;
import com.it.park.common.JsonObj;
import com.it.park.common.Page;
import com.it.park.constant.Constant;
import com.it.park.model.Link;
import com.it.park.model.VisitInfo;

@Controller
@RequestMapping("/admin/chart")
public class AdminChartController {
	private String rootPath=Constant.ADMIN_PATH;

	private Page page = null;
	@Autowired
	private LinkService linkService;
	@Autowired
	private VisitInfoService visitInfoService;
	
	@RequestMapping("listRows")
	@ResponseBody
	public Map<String,Object> listRows(HttpServletRequest request){

			int pageNow = Integer.parseInt(request.getParameter("page"));
			int rows = Integer.parseInt(request.getParameter("rows"));
			Map<String,Object> map_ = new HashMap<String, Object>();
			Integer total = linkService.selectTotal(map_);
			if(page != null){
				page = new Page(pageNow,total,rows);
			}else{
				page = new Page(1,total,rows);
			}
			map_.put("startPos", page.getStartPos());
			map_.put("pageSize", page.getPageSize());
			List<Link> list = linkService.selectPagination(map_);
			Map<String,Object> map  =new HashMap<String, Object>();
			map.put("total", total);
			map.put("rows", list);
			return map;
	}
	
	@RequestMapping("areaChart")
	public String areaChart(HttpServletRequest request){
			return rootPath+"chart/areaChart";
	}
	
	@RequestMapping("areaList")
	@ResponseBody
	public JsonObj areaList(HttpServletRequest request){
		JsonObj jsonObj = new JsonObj();
		List<VisitInfo> list = visitInfoService.selectByArea();
		jsonObj.setObject(list);
		return jsonObj;
	}
	
}
